<script setup>
import {ref } from "vue";
import { convertTimestampToDate } from "@/utils/date.js";
import { myRents } from "@/constants/mock.js";
import NavBar from "@/components/NavBar/index.vue";
import RentHistory from "@/components/RentHistory/RentHistory.vue";

// contact
// form
// list
const serviceDetailType = ref("");

// 车损上报
// 更换车辆
// 维修上报
const contactType = ref("");

// 延长租期
// 提前退车
const formType = ref("");

const buttons = [
  "延长租期",
  "车损上报",
  "提前退车",
  "更换车辆",
  "维修上报",
  "查看记录",
];

const datePicker = ref(null);

const serviceForm = ref({
  date: undefined,
  desc: undefined,
});

function handleButtonClick(label) {
  switch (label) {
    case "延长租期":
    case "提前退车":
      serviceDetailType.value = "form";
      formType.value = label;
      break;
    case "车损上报":
    case "更换车辆":
    case "维修上报":
      serviceDetailType.value = "contact";
      contactType.value = label;
      break;
    case "查看记录":
      serviceDetailType.value = "list";
      break;
  }
}

function navigateToService() {
  uni.switchTab({
    url: "/pages/Service/index",
  });
}
</script>

<template>
  <div class="container">
    <NavBar></NavBar>
    <div @click="navigateToService" class="back-nav">
      <image
        src="@/static/icon/chevron-left.png"
        style="width: 14px; height: 14px"
      ></image>
      <text>选择服务</text>
    </div>
    <div class="service-detail-content">
      <div class="service-buttons">
        <button
          v-for="(label, index) in buttons"
          :key="index"
          @click="handleButtonClick(label)"
          class="service-button"
        >
          {{ label }}
        </button>
      </div>
      <div class="service-detail">
        <div class="contact" v-if="serviceDetailType === 'contact'">
          <div class="contact-header">
            <div class="contact-type">
              {{ contactType }}
            </div>
            <div class="contact-header-desc">请联系司管进行下一步操作</div>
          </div>
          <div class="contact-footer">
            <div class="contact-footer-desc">请确认是否即刻联系司管</div>
            <div class="comfirm-button-cotainer">
              <button class="comfirm-button">是</button>
            </div>
          </div>
        </div>
        <div class="form" v-else-if="serviceDetailType === 'form'">
          <div class="form-header">{{ formType }}</div>
          <div class="date">
            <uv-datetime-picker
              ref="datePicker"
              v-model="serviceForm.date"
              mode="date"
              @confirm="(e) => (serviceForm.date = e.value)"
            >
            </uv-datetime-picker>
            <div @click="datePicker.open()" class="date-button">
              {{ convertTimestampToDate(serviceForm.date) || "选择更改日期" }}
              <image
                src="@/static/icon/calendar.png"
                class="date-button-icon"
              />
            </div>
          </div>
          <div class="desc">
            <uv-textarea
              v-model="serviceForm.desc"
              placeholder="更改事由（选填）"
            ></uv-textarea>
          </div>
          <div class="form-footer">
            <div class="comfirm-button-container">
              <button class="comfirm-button">确认</button>
            </div>
          </div>
        </div>
        <div class="list" v-else-if="serviceDetailType === 'list'">
          <div class="list-header">查看记录</div>
          <div class="historys"> <RentHistory v-for="rent in myRents"
          :key="rent"
          :rentInfo="rent"
          /></div>
         
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  background: linear-gradient(180deg, #c3e4b3 0%, #f5fff0 100%);
}

.back-nav {
  width: 100%;
  height: 20px;
  display: flex;
  justify-content: flex-start;
  margin: 20px 0;
  align-items: center;
  column-gap: 8px;
  font-size: 16px;
}

.service-buttons {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  row-gap: 10px;
  column-gap: 20px;
}

.service-button {
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  margin: 10px 0 0 0;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(90deg, #026217 0%, #04c82f 100%);
  border-radius: 10px;
  box-sizing: border-box;
}

.service-detail {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding-top: 20px;
}

.contact-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  row-gap: 14px;
}

.contact-footer {
  width: 100%;
  margin-left: -20px;
  position: fixed;
  bottom: 40px;
}

.contact-footer-desc {
  width: 100%;
  display: flex;
  justify-content: center;
}

.comfirm-button-cotainer {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0 20px;
  box-sizing: border-box;
}

.comfirm-button {
  width: 100%;
  height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  margin: 10px 0 0 0;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(90deg, #026217 0%, #04c82f 100%);
  border-radius: 10px;
  box-sizing: border-box;
}

.form {
  width: 100%;
  display: flex;
  flex-direction: column;
  row-gap: 20px;
}

.date-button {
  width: 100%;
  height: 48px;
  display: flex;
  align-items: center;
  padding-left: 16px;
  box-sizing: border-box;
  font-size: 16px;
  background-color: #f7fff3;
  color: #00000080;
  border: none;
  box-shadow: none;
  outline: none;
  border-radius: 8px;
}

.date-button-icon {
  padding-left: 8px;
  width: 18px;
  height: 18px;
}

:deep(.uv-textarea) {
  height: 100px;
  padding: 14px !important;

  background-color: #f7fff3 !important;
  color: #00000080 !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  box-sizing: border-box;
  border-radius: 10px !important;
}

:deep(.uv-textarea__field) {
  color: #00000080 !important;
  font-size: 16px !important;
}

.form-footer {
  width: calc(100% - 40px);

  position: fixed;
  bottom: 40px;
}

.historys {
  width: 100%;
  height: calc(100vh - 380px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  row-gap: 20px;
  margin-top: 20px;
}
</style>
